<?php
$this->breadcrumbs=array(
	TextbooksModule::t('Change Campus') => Yii::app()->createUrl('/textbooks/selectUniversity'),
	TextbooksModule::t($university->name) => Yii::app()->createUrl('/textbooks/department/index',array('university_id'=>$university->id)),
	TextbooksModule::t($department->name) . " ({$department->books})",
);
?>

<form class="well form-inline" method="GET" action="<?php echo Yii::app()->createUrl('/textbooks/book/list', array('department_id'=>$department->id)); ?>">
	<?php echo 'Show only books in ' . CHtml::dropDownList('course_id', $course_id, CMap::mergeArray(array('0'=>'[Select one]'), CHtml::listData($department->courses, 'id', 'name'))); ?>
	<?php echo CHtml::textField('search', $search, array('class'=>'span3', 'placeholder'=>'Search for a textbook here...')); ?>
	<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'icon'=>'search', 'label'=>'Search')); ?>
	<?php //$this->widget('bootstrap.widgets.BootButton', array('type'=>'primary', 'icon'=>'plus', 'label'=>'Post a new book', 'htmlOptions'=>array('class'=>'pull-right', 'data-target'=>'#modalPostBook', 'data-toggle'=>'modal'))); ?>
	<a class="pull-right btn btn-primary" href="<?php echo Yii::app()->createUrl('/textbooks/book/post', array('department_id'=>$department->id)); ?>"><i class="icon-plus icon-white"></i> Post a new book</a>
</form>

<?php /*$this->beginWidget('bootstrap.widgets.BootModal', array('id'=>'modalPostBook')); ?>
<form class="h-textbooks-form-post-book form-horizontal modal-form" action="<?php echo Yii::app()->createUrl('/textbooks/book/post'); ?>" method="POST">
	<?php echo CHtml::hiddenField('TextbookBook[thumbnail]', ''); ?>
	<?php echo CHtml::hiddenField('TextbookBook[google_api_json]', ''); ?>
	<div class="modal-header">
		<a class="close" data-dismiss="modal">&times;</a>
		<h3>Post a new book</h3>
	</div>
	<div class="modal-body">
		<fieldset>
			<div class="control-group">
				<?php echo CHtml::label(TextbooksModule::t('Department'), 'TextbookBook_department_id', array('class'=>'control-label')); ?>
				<div class="controls">
					<?php echo CHtml::dropDownList('TextbookBook[department_id]', $department->id, CHtml::listData($university->departments, 'id', 'name'), array('class'=>'span3')); ?>
					<div class="errorMessage errorField_department_id"></div>
				</div>
			</div>
			
			<div class="control-group">
				<?php echo CHtml::label(TextbooksModule::t('ISBN'), 'TextbookBook_isbn', array('class'=>'control-label')); ?>
				<div class="controls">
					<?php echo CHtml::textField('TextbookBook[isbn]', '', array('class'=>'span3')); ?>
					<a title="Search Information" class="h-textbooks-books-link-search-isbn" href="#"><i class="icon-search"></i></a>
					<div class="errorMessage errorField_isbn"></div>
				</div>
			</div>
			
			<div class="h-textbooks-div-hidden" style="display:none">
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Course'), 'TextbookBook_course_name', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php $this->widget('bootstrap.widgets.BootTypeahead', array(
							'id' => 'TextbookBook_course_name',
							'options'=>array(
								'source'=>array_values(CHtml::listData($courses, 'id', 'name')),
								'items'=>4,
								'matcher'=>"js:function(item) {
									return ~item.toLowerCase().indexOf(this.query.toLowerCase());
								}",
							),
							'htmlOptions' => array(
								'name' => 'TextbookBook[course_name]',
								'class' => 'span3',
								'autocomplete' => 'off',
							),
						)); ?>
						<div class="errorMessage errorField_name"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Title'), 'TextbookBook_title', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[title]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_title"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Price'), 'TextbookBook_price', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[price]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_price"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Phone'), 'TextbookBook_phone', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[phone]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_phone"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Author'), 'TextbookBook_author', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textField('TextbookBook[author]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_author"></div>
					</div>
				</div>
				
				<div class="control-group">
					<?php echo CHtml::label(TextbooksModule::t('Description'), 'TextbookBook_description', array('class'=>'control-label')); ?>
					<div class="controls">
						<?php echo CHtml::textArea('TextbookBook[description]', '', array('class'=>'span3')); ?>
						<div class="errorMessage errorField_description"></div>
					</div>
				</div>
			</div>
		</fieldset>
	</div>
	<div class="modal-footer">
		<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'type'=>'primary', 'label'=>'Add', 'icon'=>'ok')); ?>
		<?php $this->widget('bootstrap.widgets.BootButton', array('label'=>'Close', 'icon'=>'remove', 'url'=>'#', 'htmlOptions'=>array('data-dismiss'=>'modal'))); ?>
	</div>
</form>
<?php $this->endWidget();*/ ?>

<div class="row">
	<div class="span7">
		<?php foreach ($books as $book) : ?>
		<div class="h-book-item">
			<img class="thumbnail" src="<?php if ($book->thumb) echo $book->thumb; ?>" />
			<div class="h-float-right">
				<div class="h-book-content">
					<h3><?php echo CHtml::link($book->title, array('/textbooks/book/details/book_id/'.$book->id)); ?></h3>
					<p><b>Course: <?php echo CHtml::encode($book->course->name); ?></b> - ISBN #: <?php echo CHtml::encode($book->isbn); ?></p>
					<?php if ($book->author) : ?><p>Author: <?php echo CHtml::encode($book->author); ?></p><?php endif; ?>
					<?php if ($book->phone) : ?><p>Phone Number: <?php echo CHtml::encode($book->phone); ?></p><?php endif; ?>
					<p>Post by <a href="#"><?php echo CHtml::encode($book->email); ?></a> - <?php echo date('F d, Y h:i a', $book->created); ?></p>
					<p>Description: <?php echo TextHelper::word_limiter(CHtml::encode($book->description), 30); ?></p>
				</div>
				<div class="h-price-wrap">
					<span class="h-tag-head"> </span>
					<p class="h-post-price">$<?php echo $book->price; ?></p>
				</div>
			</div>
		</div>
		<?php endforeach; ?>
		<?php if (count($books) == 0) : ?>
		<div class="well">
			There are no results
		</div>
		<?php endif; ?>
		<?php $this->widget('bootstrap.widgets.BootPager', array(
			'header' => '',
			'pages' => $pages,
			'htmlOptions' => array('class'=>'pagination h-book-item'),
		)); ?>
	</div>
	<div class="span5">
		<div class="well">
			<h3>Comment for this department</h3>
			<?php $this->widget(Yii::app()->getModule('social')->getWidget('HSocialCommentsWidget'), array(
				'href' => Yii::app()->createAbsoluteUrl('/textbooks/book/list', array('deparment_id'=>$department->id)),
			)); ?>
		</div>
	</div>
</div>